package com.by.ui.tag;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.by.and_widget.FlowLayout;
import com.by.ui.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 测试标签TagLayout
 */
public class TagActivity extends AppCompatActivity {
    List<String> data = new ArrayList<>();

    private FlowLayout mFlowLayout;
    private BaseAdapter mAdapter = new BaseAdapter() {


        @Override
        public int getCount() {
            return data.size();
        }

        @Override
        public String getItem(int i) {
            return data.get(i);
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            TextView text = new TextView(TagActivity.this);
            text.setBackgroundColor(Color.CYAN);
            text.setText(getItem(i));
            return text;
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tag);
        data.add("太阳");
        data.add("月亮");
        data.add("星星");
        data.add("学生");
        data.add("大学生");
        data.add("Android VS IOS");
        data.add("搜狗输入法");
        data.add("Android Studio");
        data.add("Win7");
        data.add("Chrome浏览器");
        mFlowLayout = (FlowLayout) findViewById(R.id.flow_layout);
        mFlowLayout.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(TagActivity.this, data.get(i), Toast.LENGTH_SHORT).show();
            }
        });
        mFlowLayout.setAdapter(mAdapter);

        findViewById(R.id.btn_add_tag).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                data.add("搜狗输入法1");
                data.add("搜狗输入法2");
                data.add("搜狗输入法1");
                data.add("搜狗输入法2");
                data.add("搜狗输入法1");
                mAdapter.notifyDataSetChanged();
            }
        });

        findViewById(R.id.btn_delete_tag).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                data.remove("太阳");
                data.remove("月亮");
                data.remove("Android Studio");
                data.remove("Win7");
                data.remove("Chrome浏览器");

                mAdapter.notifyDataSetChanged();
            }
        });

    }


}
